<!--
 * @Author: MarioGo
 * @Date: 2021-11-04 22:57:03
 * @LastEditTime: 2021-11-19 22:34:51
 * @LastEditors: MarioGo
 * @Description: 文件描述
 * @FilePath: /zheye/src/components/ColumnList.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->
<template>
  <div class="row">
    <div v-for="column in columnList" :key="column.id" class="col-4 mb-4">
      <div class="card h-100 shadow-sm">
        <img class="card-img-top" :src="column.avatar" :alt="column.title" />
        <div class="card-body">
          <h5 class="card-title">{{ column.title }}</h5>
          <p class="card-text">{{ column.description }}</p>
          <router-link :to="`/column/${column.id}`" class="btn btn-outline-primary"
            >进入专栏
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue';
import { ColumnProps } from '../store';

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>, // 构造函数 断言成 数组
      required: true,
    },
  },
  setup(props) {
    const columnList = computed(() => {
      return props.list.map((column) => {
        if (!column.avatar) {
          column.avatar = require('@/assets/noimag.jpg');
        }
        return column;
      });
    });
    return {
      columnList,
    };
  },
});
</script>
